package com.zoweunion.mechanic.controller.base;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.model.ResponseBean;
import com.zoweunion.mechanic.model.User;
import com.zoweunion.mechanic.service.base.WarningService;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.MyException;
/**
 * @Description:  故障报警控制层 
 * @author: yumeng 
 * @date:   2018年10月12日 下午1:24:15    
 * @Copyright: 2018 www.zoweunion.com Inc. All rights reserved.
 */
@RestController
@RequestMapping("/warning")
@SuppressWarnings("unchecked")
public class WarningController extends BaseController{
	
	@Autowired
	private WarningService warningService;

	/**
	 * 获取待处理报警列表
	 */
	@PostMapping("/dclList")
	public ResponseBean dclList(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "故障报警管理_待处理列表展示");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		 User user = getCurrentUser(request);
		if (null != user) {
			reqMap.put("s_id", user.getS_id());
			reqMap.put("handle_status",1); //1:未处理
			Map<String, Object> resultMap=warningService.getPageQuery(reqMap);
			logAfter(logger);
			return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
		}else {
			return new ResponseBean(Constants.CODE_ERROR,"操作失败,用户没有登录",null);
		}
		
	}
	
	/**
	 * 获取待处理报警列表
	 */
	@PostMapping("/historyList")
	public ResponseBean list(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "故障报警管理_历史列表展示");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		reqMap.put("handle_status",2); //2:已处理
		Map<String, Object> resultMap=warningService.getPageQuery(reqMap);
		logAfter(logger);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}
	
	
	/**
	 * 获取报警详情
	 */
	@PostMapping("/getWarningInfo")
	public ResponseBean getWarningInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "故障报警管理_报警详情");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		List<Map<String, Object>> resultList=warningService.getWarningInfo(reqMap);
		logAfter(logger);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
}
